package org.wltea.analyzer.utils;

import java.io.IOException;
import java.io.Reader;
import java.util.HashMap;
import java.util.Map;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.synonym.SynonymFilterFactory;
import org.apache.lucene.analysis.util.FilesystemResourceLoader;
import org.wltea.analyzer.lucene.IKTokenizer;

public class IKSynonymsAnalyzer extends Analyzer {
	@Override
	protected TokenStreamComponents createComponents(String arg0, Reader arg1) {
		Tokenizer token = new IKTokenizer(arg1, false);// 开启智能切词
		Map paramsMap = new HashMap();
		paramsMap.put("luceneMatchVersion", "LUCENE_43");
		paramsMap.put("synonyms", "C:\\同义词\\synonyms.txt");
		SynonymFilterFactory factory = new SynonymFilterFactory(paramsMap);
		// factory.
		FilesystemResourceLoader loader = new FilesystemResourceLoader();
		try {
			factory.inform(loader);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return new TokenStreamComponents(token, factory.create(token));
	}

}